package com.tuling.mall;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableScheduling   // 开启定时任务功能
public class NacosConfigMain {
    public static void main(String[] args) throws Exception{
        ConfigurableApplicationContext applicationContext =  SpringApplication.run(NacosConfigMain.class,args);
        System.out.println("nacos config 启动了......");

//        String userName = applicationContext.getEnvironment().getProperty("common.name");
//        String userAge = applicationContext.getEnvironment().getProperty("common.age");
//        System.out.println("common name :"+userName+"; age: "+userAge);

        while (true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔3秒中从Enviroment中获取配置
            String userName = applicationContext.getEnvironment().getProperty("common.name");
            String userAge = applicationContext.getEnvironment().getProperty("common.age");
            System.err.println("common name:" + userName + "; age: " + userAge);
            TimeUnit.SECONDS.sleep(3);

        }
    }
}